import "pkl:test"

class Person {
  name: String
}

res1 = new Person { name = "Pigeon" }

res2 {
  prop = new Person { name = "Pigeon" }

  new Person { name = "Pigeon" }

  ["Pigeon"] = new Person { name = "Pigeon" }
}

res3 = new Listing {
  new Person { name = "Pigeon" }
}
res4 = (res3) {
  [0] = new Person { name = "Pigeon" }
}

res5 = new Listing<Person> {
  new Person { name = "Pigeon" }
  new { name = "Barn Owl" }
}
res6 = (res5) {
  [0] = new { name = "Pigeon2" }
  [1] { name = "Barn Owl2" }
}

res7 = new Mapping<String, Person> {
  ["Pigeon"] = new Person { name = "Pigeon" }
  ["Barn Owl"] = new { name = "Barn Owl" }
  ["Parrot"] { name = "Parrot" }
}
res8 = (res7) {
  ["Pigeon"] = new { name = "Pigeon2" }
  ["Barn Owl"] { name = "Barn Owl2" }
}

local mixin1 = new Mixin { name = "Other" }
res9 = new Person { name = "Pigeon" } |> mixin1
res9b = test.catch(() -> mixin1.apply(new Person {}, new Person {}))

local mixin2 = (mixin1) { name = "Override" }
res9c = new Person { name = "Pigeon" } |> mixin2
res9d = test.catch(() -> mixin2.apply(new Person {}, new Person {}))

local mixin3 = new Mixin<Person> { name = "Other" }
res10 = new Person { name = "Pigeon" } |> mixin3
res10b = test.catch(() -> mixin3.apply(new Person {}, new Person {}))
res10c = test.catch(() -> mixin3.apply(1))

local mixin4 = (mixin3) { name = "Override" }
res10d = new Person { name = "Pigeon" } |> mixin4
res10e = test.catch(() -> mixin4.apply(new Person {}, new Person {}))
res10f = test.catch(() -> mixin4.apply(1))

typealias Person2 = Person
res11 = new Person2 { name = "Pigeon" }

typealias PersonMapping = Mapping<String, Person>
res12 = new PersonMapping {
  ["Pigeon"] = new Person { name = "Pigeon" }
  ["Barn Owl"] = new { name = "Barn Owl" }
  ["Parrot"] { name = "Parrot" }
}

res13 = new Person? { name = "Pigeon" }

res14 = new *Person|String { name = "Pigeon" }

res15 = test.catch(() -> new Int {})

res16 = test.catch(() -> new Set {})

res17 = test.catch(() -> new String|Person {})

res18 = test.catch(() -> new "foo" {})
